import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By


def main():
    """"""
    driver = webdriver.Chrome()
    driver.get("https://www.selenium.dev/selenium/web/web-form.html")
    driver.implicitly_wait(0.5)
    text_box = driver.find_element(by=By.NAME, value="my-text")
    submit_button = driver.find_element(by=By.CSS_SELECTOR, value="button")
    text_box.send_keys("Selenium")
    submit_button.click()
    message = driver.find_element(by=By.ID, value="message")
    text = message.text
    print(text)
    driver.quit()


def main2():
    """"""
    url = "https://accounts.douban.com/passport/login?source=movie"
    driver = webdriver.Chrome()
    driver.get(url)
    driver.implicitly_wait(1)
    username = driver.find_element(by=By.CSS_SELECTOR,
                                   value="#account > div.login-wrap > div.login-right > div > div.account-tabcon-start > div.account-form > div:nth-child(3) > div > input")
    username.send_keys('gengxuelong')
    driver.quit()


from selenium.webdriver.chrome.options import Options


def login_doban(username_input='13937825104', password_input='Gxl2236035.'):
    url = "https://accounts.douban.com/passport/login?source=movie"
    options = Options()
    options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
    driver = webdriver.Chrome(options=options)
    driver.get(url)
    driver.implicitly_wait(3)
    mimadenglu = driver.find_element(by=By.CSS_SELECTOR,
                                     value="#account > div.login-wrap > div.login-right > div > div.account-body-tabs > ul.tab-start > li.account-tab-account")
    mimadenglu.click()
    driver.implicitly_wait(1)
    # username = driver.find_element(by=By.CSS_SELECTOR,
    #                                value="#username")
    # username.send_keys(username_input)
    # password = driver.find_element(by=By.CSS_SELECTOR, value='#password')
    # password.send_keys(password_input)
    a_button = driver.find_element(by=By.CSS_SELECTOR,
                                   value='#account > div.login-wrap > div.login-right > div > div.account-tabcon-start > div.account-form > div.account-form-field-submit > a')
    a_button.click()
    driver.implicitly_wait(5)
    html = driver.page_source
    with open("test.html", "w", encoding="utf-8") as f:
        f.write(html)
    # driver.quit()


def visit_doban():
    """"""
    url = "https://www.douban.com/"
    options = Options()
    options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
    driver = webdriver.Chrome(options=options)
    driver.get(url)

if __name__ == '__main__':
    visit_doban()
